<html>
<head>
	<meta charset="UTF-8">
	<meta content="IE=edge" http-equiv="X-UA-Compatible">
	<meta content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width" name="viewport">
	<title>2366：多重历史</title>
	<!-- css -->
	<link href="../css/base.min.css" rel="stylesheet">
	<link href="../css/project.min.css" rel="stylesheet">
	
	<!-- favicon -->
	<!-- ... -->
</head>
<body class="page-brand">
	<header class="header header-transparent header-waterfall ui-header">
		<ul class="nav nav-list pull-left">
			<li>
				<a data-toggle="menu" href="#menu">
					<span class="icon icon-lg">menu</span>
				</a>
			</li>
		</ul>
		<a class="header-logo header-affix-hide margin-left-no margin-right-no" data-offset-top="213" data-spy="affix">多重历史</a>
		<span class="header-logo header-affix margin-left-no margin-right-no" data-offset-top="213" data-spy="affix">多重历史</span>
	</header>
	<nav aria-hidden="true" class="menu" id="menu" tabindex="-1">
		<div class="menu-scroll">
			<div class="menu-content">
				<a class="menu-logo" href="../index.html">BZOJ离线题库</a>
				<ul class="nav">
					<li>
						<a class="waves-attach" data-toggle="collapse" href="#problems">题目</a>
						<ul class="menu-collapse collapse in" id="problems">
							<li>
								<a class="waves-attach" href="../index.html">主页</a>
							</li>
							<li>
								<a class="waves-attach" href="../list.html">题目列表</a>
							</li>
						</ul>
					</li>
					<li>
						<a class="collapsed waves-attach" data-toggle="collapse" href="#about">关于</a>
						<ul class="menu-collapse collapse" id="about">
							<li>
								<a class="waves-attach" href="../about.html">关于此项目</a>
							</li>
						</ul>
					</li>
					
				</ul>
			</div>
		</div>
	</nav>
	<main class="content">
		<div class="content-header ui-content-header">
			<div class="container">
				<h1 class="content-heading">
                多重历史                </h1>
                <p>时间限制：2s&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  空间限制：128MB</p>			</div>
		</div>
		<div class="container">
			<section class="content-inner margin-top-no">
				<div class="row">
					<div class="col-lg-13 col-md-13">
						<div class="card margin-bottom-no">
							<div class="card-main">
								<div class="card-inner">
									
                                <h3>题目描述</h3><p><h2 align="center" style="text-align:center"></h2>
<h3 style="margin-top:6.0pt;margin-right:0cm;margin-bottom:0cm;margin-left:
0cm;margin-bottom:.0001pt;line-height:172%"><br />
<i style="mso-bidi-font-style:
normal"><span style="mso-bidi-font-size:10.5pt;font-family:宋体;mso-ascii-font-family:
&quot;Courier New&quot;;mso-bidi-font-family:&quot;Courier New&quot;">宇宙具有多重历史，每一个历史都是由微小的硬果决定的。</span></i><i style="mso-bidi-font-style:normal"><span lang="EN-US" style="mso-bidi-font-size:
10.5pt;font-family:&quot;Courier New&quot;"><span style="mso-spacerun:yes">&nbsp;&nbsp; </span>&mdash;&mdash;</span></i><i style="mso-bidi-font-style:normal"><span style="mso-bidi-font-size:10.5pt;
font-family:宋体;mso-ascii-font-family:&quot;Courier New&quot;;mso-bidi-font-family:&quot;Courier New&quot;">霍金《果壳中的宇宙》</span></i><i style="mso-bidi-font-style:normal"><span lang="EN-US" style="mso-bidi-font-size:
10.5pt;font-family:&quot;Courier New&quot;;mso-hansi-font-family:宋体"><o:p></o:p></span></i></h3>
<p class="MsoNormal" style="text-indent:21.0pt"><i><br />
</i><span lang="EN-US" style="mso-bidi-font-size:10.5pt;
font-family:&quot;Courier New&quot;"><span style="mso-spacerun:yes">&nbsp;&nbsp; </span></span><span lang="EN-US" style="mso-bidi-font-size:10.5pt;font-family:华文细黑;mso-bidi-font-family:
&quot;Courier New&quot;"><span style="mso-spacerun:yes">&nbsp;</span>TIGER</span><span style="mso-bidi-font-size:10.5pt;font-family:华文细黑;mso-bidi-font-family:&quot;Courier New&quot;">实验室的<span lang="EN-US" style="color:black">Dr.</span><span lang="EN-US">Minimum</span>对现代理论物理学中的多重历史理论特别感兴趣。有一次，他给擅长计算的研究员<span lang="EN-US">Maximum</span>出了一个难题：<span lang="EN-US">&ldquo;</span>假设在过去的一段连续时间中，每一个时刻只有可能发生一个<b style="mso-bidi-font-weight:normal">动作</b>（当然也可能不发生）。一段<b style="mso-bidi-font-weight:
normal">连续时间</b>里发生的某些特定的动作序列称作一个<b style="mso-bidi-font-weight:normal">事件</b>。现在我只告诉你，过去一段时间的可能动作列表，以及在那一段时间内发生的事件、事件的内容（也就是事件是有哪些动作连续构成）以及事件发生的先后顺序。要你求出有多少个可能的<b style="mso-bidi-font-weight:normal">历史</b>。<span lang="EN-US"><o:p></o:p></span></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-bidi-font-size:10.5pt;
font-family:华文细黑;mso-bidi-font-family:&quot;Courier New&quot;"><span style="mso-spacerun:yes">&nbsp;</span><span style="mso-spacerun:yes">&nbsp;&nbsp; </span></span><span style="mso-bidi-font-size:10.5pt;font-family:华文细黑;mso-bidi-font-family:&quot;Courier New&quot;">我们把相同的动作用相同的小写字母表示，那么<b style="mso-bidi-font-weight:normal">可能的动作列表</b>和<b style="mso-bidi-font-weight:
normal">事件</b>都可以表示为一个字符串。假设有两个动作，<span lang="EN-US">a</span>和<span lang="EN-US">b</span>，假设过去一段时间内，可能发生的动作列表为<span lang="EN-US">&rsquo;aabb&rsquo;</span>，发生的事件为<span lang="EN-US">&rsquo;a&rsquo;</span>，<span lang="EN-US">&rsquo;b&rsquo;</span>，<span lang="EN-US">&rsquo;a&rsquo;</span>在<span lang="EN-US">&rsquo;b&rsquo;</span>之前发生，那么一共就可能有<span lang="EN-US">4</span>种不同的历史，分别为<span lang="EN-US" style="color:red">a</span><span lang="EN-US">a<span style="color:red">b</span>b</span>、<span lang="EN-US" style="color:red">a</span><span lang="EN-US">ab<span style="color:
red">b</span></span>、<span lang="EN-US">a<span style="color:red">ab</span>b</span>、<span lang="EN-US">a<span style="color:red">a</span>b<span style="color:red">b</span></span>（红色表示发生的动作）。但是，如果事件为<span lang="EN-US">&rsquo;aab&rsquo;</span>，<span lang="EN-US">&rsquo;abb&rsquo;</span>，而且<span lang="EN-US">&rsquo;aab&rsquo;</span>比<span lang="EN-US">&rsquo;abb&rsquo;</span>先发生，那么对于上述的可能动作列表，就不存在满足要求的历史（因为事件是相对独立的，不能交错）。<span lang="EN-US"><o:p></o:p></span></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-bidi-font-size:10.5pt;
font-family:华文细黑;mso-bidi-font-family:&quot;Courier New&quot;"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span></span><span style="mso-bidi-font-size:
10.5pt;font-family:华文细黑;mso-bidi-font-family:&quot;Courier New&quot;">如果你是<span lang="EN-US">Maximum</span>，如何解决这个问题呢？<span lang="EN-US"><o:p></o:p></span></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<h3 style="margin:0cm;margin-bottom:.0001pt;line-height:172%"></h3>
<p></p></p><hr/><h3>输入格式</h3><p><h3 style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; line-height: 24px; "><br />
<span lang="EN-US" style="font-family: 'Courier New'; "><span>&nbsp;&nbsp;&nbsp;</span></span><span lang="EN-US" style="font-family: 华文细黑; "><span>&nbsp;</span></span><span style="font-family: 华文细黑; ">输入文件第一行为一个数<i><span lang="EN-US">N</span></i>，表示事件的个数。接下来<span lang="EN-US">n</span>行每行一个字符串，按时间顺序给出每个事件（所有事件字符串长度和不大于<span lang="EN-US">10000</span>，并且不存在两个事件字符串<i><span lang="EN-US">A</span></i>和<i><span lang="EN-US">B</span></i>，<i><span lang="EN-US">A</span></i>是<i><span lang="EN-US">B</span></i>的后缀）。最后一行为一个字符串，表示过去一段时间里可能的动作列表（长度不大于<span lang="EN-US">500000</span>）<span lang="EN-US"><o:p></o:p></span></span></h3>
<h3 style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; line-height: 24px; "></h3>
<p class="MsoNormal"></p>
<p></p></p><hr/><h3>输出格式</h3><p><h3 style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; line-height: 24px; "><span lang="EN-US" style="font-family: 'Courier New'; "><span>&nbsp;&nbsp; &nbsp;</span></span><span style="font-family: 华文细黑; ">输出文件包含一个整数，表示可能的历史总数对<span lang="EN-US">1000000</span>取余的结果。</span></h3>
<p></p></p><hr/><h3>样例输入</h3><pre>2
a
b
aabb
</pre><hr/><h3>样例输出</h3><pre>4</pre><hr/><h3>提示</h3><p>没有写明提示</p><hr/><h3>题目来源</h3><p>没有写明来源</p>
								</div>
							</div>
						</div>
					</div>
				</div>
				
				
			</section>
		</div>
	</main>

	<div class="fbtn-container">
		<div class="fbtn-inner">
			<a class="fbtn fbtn-lg fbtn-brand-accent waves-attach waves-circle waves-light waves-effect" data-toggle="dropdown" aria-expanded="true"><span class="fbtn-text fbtn-text-left">Menu</span><span class="fbtn-ori icon">apps</span><span class="fbtn-sub icon">close</span></a>
			<div class="fbtn-dropup">
				<a class="fbtn fbtn-brand waves-attach waves-circle waves-light waves-effect" href="../list.html" target="_self"><span class="fbtn-text fbtn-text-left">题目列表</span><span class="icon">menu</span></a>
				<a class="fbtn fbtn-green waves-attach waves-circle waves-effect" href="../index.html" target="_self"><span class="fbtn-text fbtn-text-left">返回主页</span><span class="icon">home</span></a>
				<a class="fbtn waves-attach waves-circle waves-effect" href="http://www.lydsy.com/JudgeOnline/submitpage.php?id=2366" target="_blank"><span class="fbtn-text fbtn-text-left">提交代码</span><span class="icon">send</span></a>
				<a class="fbtn fbtn-orange waves-attach waves-circle waves-effect" href="http://www.lydsy.com/JudgeOnline/wttl/wttl.php?pid=2366" target="_blank"><span class="fbtn-text fbtn-text-left">试题讨论</span><span class="icon">chat</span></a>
				
			</div>
		</div>
	</div>

	<!-- js -->
	<script src="../js/jquery.min.js"></script>
	<script src="../js/base.min.js"></script>
	<script src="../js/project.min.js"></script>
</body>
</html>